package com.jiangjiang.eshop.commodity.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.commodity.convert.GoodsDetailConvert;
import com.jiangjiang.eshop.commodity.dao.GoodsDetailMapper;
import com.jiangjiang.eshop.commodity.domain.GoodsDetailEntity;
import com.jiangjiang.eshop.commodity.dto.GoodsDetailDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName GoodsDetailService
 * @Description TODO
 * @Author jhw
 * @Date 2021/8/2 17:44
 * @Version 1.0
 **/
@Service
public class GoodsDetailService extends ServiceImpl<GoodsDetailMapper, GoodsDetailEntity> {

    @Autowired
    private GoodsDetailConvert goodsDetailConvert;

    /**
     * 根据商品id查询商品明细数据
     * @param goodsId 商品id
     * @return 商品详情页数据
     */
    public GoodsDetailDTO queryByGoodsId(Long goodsId) {
        LambdaQueryWrapper<GoodsDetailEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(GoodsDetailEntity::getGoodsId, goodsId);
        return goodsDetailConvert.convertEntity2DTO(this.getOne(wrapper));
    }

    /**
     * 保存商品详情也
     * @param detailDTO 商品详情页数据
     * @return 处理结果
     */
    public Boolean saveGoodsDetail(GoodsDetailDTO detailDTO) {
        return this.save(goodsDetailConvert.convertDTO2Entity(detailDTO));
    }

    /**
     * 更新商品详情也数据
     * @param detailDTO 商品详情页数据
     * @return 处理结果
     */
    public Boolean updateGoodsDetail(GoodsDetailDTO detailDTO) {
        return this.updateById(goodsDetailConvert.convertDTO2Entity(detailDTO));
    }
}
